<!--
    /**
     * 字典树形下拉选择组件：继承自树形下拉选择组件
     * @see @/components/TreeSelect
     * 使用方法
     * <dict-tree-select v-model="form.entry.parentId" :readonly="!form.editable" :key="form.entry.id"></dict-tree-select>
     */
-->
<script>
/**
 * 数据字典树形下拉选择组件：继承自树形下拉选择组件
 * @see @/components/TreeSelect
 */
import TreeSelect from "@/components/TreeSelect";
import *  as systemDictionaryApi from '../apis/dictionary'

export default {
  /*继承会优先调度原组件所有操作，再调度当前组件中重写内容; 解析执行顺序如下：
  继承：data---------------
  原：data---------------
  原：created---------------
  继承：created---------------
  原：mounted---------------
  继承：initSelected---------------
  继承：mounted---------------
  继承：initSelected---------------
  继承组件中重写同名属性、方法会覆盖原组件属性、方法
   */
  extends: TreeSelect,
  name: 'dict-tree-select',
  props: {
    clearable: {
      type: Boolean, default() {
        return true
      }
    },
    nodeProps: {
      type: Object, default() {
        return {children: 'children', label: 'name',}
      }
    },
    nodeKey: {
      type: String, default() {
        return 'id'
      }
    },
  },
  data() {
    return {
      treeData: []
    };
  },
  mounted() {
    if (!(this.nodeData && this.nodeData.length > 0)) {
      this.loadData()
    }
  },
  methods: {
    loadData() {
      systemDictionaryApi.list({model: 'field'}).then(response => {
        if (response.status === 200) {
          this.$set(this, "treeData", this.$utils.listConvertTree(response.result))
          // this.treeData = this.$utils.listConvertTree(response.result)
          // this.handleSelectedKey()
        }
      })
    }
  },
};
</script>

